package JavaSE;

public class setAge {
    private int age;

    public void setAge(int age) {
        if (age >= 0 && age <= 150) {
            this.age = age;
        } else {
            System.out.println("Invalid age. Age must be between 0 and 150.");
        }
    }


    // 可选：添加一个方法来获取年龄
    public int getAge() {
        return age;
    }

    // 主方法用于测试Person类
    public static void main(String[] args) {
        Person person = new Person();

        // 设置合法年龄
        person.setAge(25);
        System.out.println("Person's age is: " + person.getAge());

        // 尝试设置不合法的年龄
        person.setAge(-1);
        System.out.println("Person's age is: " + person.getAge());

        // 尝试设置另一个合法年龄
        person.setAge(100);
        System.out.println("Person's age is: " + person.getAge());
    }

}
